package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.historyRFCPanel.historyRFCPanelSubs;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.historyRFCPanel.HistoryRFCPanel;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.historyRFCPanel.historyRFCPanelSubs.listeners.LoadHistoryButtonListener;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.historyRFCPanel.historyRFCPanelSubs.listeners.LoadSpecHistoryButtonListener;

public class HistoryRFCFunctionPanel extends JPanel
{
	private static final long serialVersionUID = 1L;

	private JButton btuLoadHistory, loadSpecRFCHistory;
	private JLabel progress;
	private JTextField serchfield;
	private String value = "...";
	
	public HistoryRFCFunctionPanel(HistoryRFCPanel historyRFCPanel)
	{
		this.setLayout(new BorderLayout());
		this.btuLoadHistory = new JButton("Laden der ganzen History");
		this.btuLoadHistory.addActionListener(new LoadHistoryButtonListener(historyRFCPanel));
		URL pic = getClass().getResource("/progressbar_cont.gif");
		this.progress = new JLabel(new ImageIcon(pic));
		this.progress.setVisible(false);
		
		this.serchfield = new JTextField();
		this.serchfield.addKeyListener(new KeyListener() {
			
			@Override
			public void keyTyped(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void keyReleased(KeyEvent arg0) {
				value = serchfield.getText();
				loadSpecRFCHistory.setText("History von RFC "+value +" laden");
				
			}
			
			@Override
			public void keyPressed(KeyEvent arg0) {

			}
		});
		
		this.loadSpecRFCHistory = new JButton("History von RFC "+value+" laden");
		this.loadSpecRFCHistory.addActionListener(new LoadSpecHistoryButtonListener(historyRFCPanel));
		
		this.add(new ButtonList(),BorderLayout.NORTH);
		
	}
	
	
	private class ButtonList extends JPanel
	{
		private static final long serialVersionUID = 1L;

		private ButtonList()
		{
			this.setLayout(new GridLayout(5,1));
			this.add(btuLoadHistory);
			JLabel label = new JLabel("History-Suche: RFC-ID eingeben");
			label.setFont(new Font("", Font.BOLD, 12));
			this.add(label);
			this.add(serchfield);
			this.add(loadSpecRFCHistory);
			this.add(progress);
		}
	}
		
	public JTextField getSerchfield() {
		return serchfield;
	}

	
	public JButton getLoadSpecRFCHistory() {
		return loadSpecRFCHistory;
	}


	public JLabel getProgress()
	{
		return progress;
	}
}